package com.elong.businesstravel.modules.home.hotel.adapter;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpResponse;

import android.R.integer;
import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.AnimationDrawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.handlerui.HandlerPostUI;
import com.android.support.jhf.handlerui.HandlerToastUI;
import com.android.support.jhf.network.NetworkClient;
import com.android.support.jhf.network.loopj.android.http.ResponseHandlerInterface;
import com.android.support.jhf.universalimageloader.core.ImageLoader;
import com.android.support.jhf.universalimageloader.core.assist.FailReason;
import com.android.support.jhf.universalimageloader.core.listener.ImageLoadingListener;
import com.android.support.jhf.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.android.support.jhf.utils.DateUtils;
import com.android.support.jhf.utils.ImageUtil;
import com.android.support.jhf.utils.ScreenUtils;
import com.android.support.jhf.utils.ToolUtils;
import com.elong.businesstravel.ELongBusinessTravelApplication;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.recorder.Recorder;
import com.elong.businesstravel.base.recorder.Recorder.OnStateChangedListener;
import com.elong.businesstravel.base.uploadpic.UploadPic;
import com.elong.businesstravel.base.utils.AppUserId;
import com.elong.businesstravel.entitys.HotelInfo;
import com.elong.businesstravel.entitys.HotelPrice;
import com.elong.businesstravel.entitys.HotelReviews;
import com.elong.businesstravel.entitys.MemberManaged;
import com.elong.businesstravel.entitys.OrderInfo;
import com.elong.businesstravel.entitys.HotelPrice.RatePlanInfo;
import com.elong.businesstravel.entitys.HotelPrice.RoomInfo;
import com.elong.businesstravel.modules.collect.HotelCollectActivity;
import com.elong.businesstravel.modules.home.hotel.hotelshow.HotelLocationMapActivity;
import com.elong.businesstravel.modules.home.hotel.hotelshow.HotelPictureActivity;
import com.elong.businesstravel.modules.login.LoginActivity;
import com.elong.businesstravel.modules.orders.view.OrdersView;
import com.elong.businesstravel.protocol.hotel.AddCollectionRequest;
import com.elong.businesstravel.protocol.hotel.AddCollectionResponse;
import com.elong.businesstravel.protocol.hotel.DeleteCollectionRequest;
import com.elong.businesstravel.protocol.hotel.DeleteCollectionResponse;
import com.elong.businesstravel.protocol.order.DownLoadRequest;
import com.elong.businesstravel.protocol.order.DownLoadResponse;
import com.elong.businesstravel.wxapi.WXEntryActivity;
import com.umeng.analytics.MobclickAgent;

public class HotelDetailAdapter extends BaseAdapter implements
		OnCheckedChangeListener {

	public static final String HEAD = "head";
	public static final String BUTTON = "button";
	public static final String ITEM = "item";
	public static final String DATE = "date";
	public static final String PRICE = "price";

	private static final String SAVE_VOICE_PATH = UploadPic.SDCARD_ROOT_PATH
			+ "/" + UploadPic.CLT + "/" + Recorder.RECORD + "/";

	private Context mContext;
	private ELongBusinessTravelApplication mApplication;
	private List<Object> mHotelList;
	private List<MemberManaged> mMemberManageds;
	private ArrayList<HotelInfo> mHotelInfos;
	/** 1 可以现金抵扣 0 不可以 */
	private String mDeduction;
	private int mCurrentTab = 0;
	private View mTabView;
	private Recorder mRecorder;

	private OnCheckedChangeListener mRadio0OnCheckedChangeListener;
	private OnCheckedChangeListener mRadio1OnCheckedChangeListener;
	private OnCheckedChangeListener mRadio2OnCheckedChangeListener;

	private AnimationDrawable mAnimationDrawable;
	private ImageView lastPlayAnimImageView;
	private int mPlayAnimPosition = -1;

	/**
	 * 
	 * @param context
	 * @param hotelObjects
	 * @param hotelInfos
	 * @param tabView
	 * @param memberManageds
	 * @param deduction
	 *            1 可以现金抵扣 0 不可以
	 */
	public HotelDetailAdapter(Context context, List<Object> hotelObjects,
			ArrayList<HotelInfo> hotelInfos, View tabView,
			List<MemberManaged> memberManageds, String deduction) {
		mContext = context;
		mHotelList = hotelObjects;
		mHotelInfos = hotelInfos;
		mApplication = (ELongBusinessTravelApplication) mContext
				.getApplicationContext();
		mTabView = tabView;
		mMemberManageds = memberManageds;
		mDeduction = deduction;
		mRecorder = new Recorder();
		mRecorder.setOnStateChangedListener(new OnStateChangedListener() {

			@Override
			public void onStateChanged(int state) {

			}

			@Override
			public void onError(int error) {

			}

			@Override
			public void onCompletion() {
				stopPlayback();
			}
		});
	}

	public void stopPlayback() {
		mPlayAnimPosition = -1;
		if (null != mRecorder)
			mRecorder.stopPlayback();
		if (null != lastPlayAnimImageView)
			lastPlayAnimImageView.setImageDrawable(mContext.getResources()
					.getDrawable(R.anim.record_play_wait_xml));
	}

	@Override
	public int getCount() {
		if (0 == mCurrentTab) {
			return mHotelList.size() + 3;
		} else {
			return mHotelList.size() + 2;
		}
	}

	@Override
	public Object getItem(int arg0) {
		if (0 == mCurrentTab) {
			if (0 == arg0) {
				return HEAD;
			} else if (1 == arg0) {
				return BUTTON;
			} else if (2 == arg0) {
				return DATE;
			}
			return mHotelList.get(arg0 - 3);
		} else {
			if (0 == arg0) {
				return HEAD;
			} else if (1 == arg0) {
				return BUTTON;
			}
			return mHotelList.get(arg0 - 2);
		}

	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View arg1, ViewGroup arg2) {

		if (null == arg1) {
			if (0 == arg0) {
				arg1 = LayoutInflater.from(mContext).inflate(
						R.layout.view_hotel_detail_head_item, null);
				arg1.setTag(HEAD);
			} else if (0 == mCurrentTab) {
				if (1 == arg0) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.view_hotel_detail_tab_button, null);
					arg1.setTag(BUTTON);
				} else if (2 == arg0) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.adapter_hotel_detail_date_change, null);
					arg1.setTag(DATE);
				} else {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.adapter_hotel_detail_price, null);
					arg1.setTag(PRICE);
				}
			} else {
				if (1 == arg0) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.view_hotel_detail_tab_button, null);
					arg1.setTag(BUTTON);
				} else {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.view_hotel_detail_list_item, null);
					arg1.setTag(ITEM);
				}
			}
		} else {
			if (0 == arg0 && !HEAD.equals(arg1.getTag())) {
				arg1 = LayoutInflater.from(mContext).inflate(
						R.layout.view_hotel_detail_head_item, null);
				arg1.setTag(HEAD);
			} else if (0 == mCurrentTab) {
				if (1 == arg0 && !BUTTON.equals(arg1.getTag())) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.view_hotel_detail_tab_button, null);
					arg1.setTag(BUTTON);
				} else if (2 == arg0 && !DATE.equals(arg1.getTag())) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.adapter_hotel_detail_date_change, null);
					arg1.setTag(DATE);
				} else if (0 != arg0 && 1 != arg0 && 2 != arg0
						&& !PRICE.equals(arg1.getTag())) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.adapter_hotel_detail_price, null);
					arg1.setTag(PRICE);
				}
			} else {
				if (1 == arg0 && !BUTTON.equals(arg1.getTag())) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.view_hotel_detail_tab_button, null);
					arg1.setTag(BUTTON);
				} else if (0 != arg0 && 1 != arg0
						&& !ITEM.equals(arg1.getTag())) {
					arg1 = LayoutInflater.from(mContext).inflate(
							R.layout.view_hotel_detail_list_item, null);
					arg1.setTag(ITEM);
				}
			}
		}

		if (0 == arg0) {
			if (1 == mHotelInfos.size()) {
				final HotelInfo hotelInfo = mHotelInfos.get(0);
				ImageView hotelFrameImageView = (ImageView) arg1
						.findViewById(R.id.hotelFrameImageView);
				final ImageView hotelImageView = (ImageView) arg1
						.findViewById(R.id.hotelImageView);
				if (hotelInfo.mHotelImages.size() > 0) {
					ImageLoader.getInstance().displayImage(
							hotelInfo.mHotelImages.get(0).location,
							hotelImageView, mApplication.mDisplayImageOptions);
				}
				hotelFrameImageView.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						MobclickAgent.onEvent(mContext,
								"Hotel_Image");
						if (hotelInfo.mHotelImages.size() == 0) {
							HandlerToastUI.getHandlerToastUI(mContext,
									"暂时没有酒店图片");
						} else {
							Intent intent = new Intent(mContext,
									HotelPictureActivity.class);
							intent.putExtra("images", hotelInfo.mHotelImages);
							mContext.startActivity(intent);
						}
					}
				});
				TextView imageNumTextView = (TextView) arg1
						.findViewById(R.id.imageNumTextView);
				imageNumTextView.setText(hotelInfo.mHotelImages.size() + "张");

				TextView hotelNameTextView = (TextView) arg1
						.findViewById(R.id.hotelNameTextView);
				hotelNameTextView.setText(hotelInfo.hotelName);

				ImageView parkingImageView = (ImageView) arg1
						.findViewById(R.id.parkingImageView);
				parkingImageView.setVisibility(View.GONE);
				ImageView wifiImageView = (ImageView) arg1
						.findViewById(R.id.wifiImageView);
				wifiImageView.setVisibility(View.GONE);
				if (!"".equals(hotelInfo.facilities)) {
					String[] facilities = hotelInfo.facilities.split(",");
					for (int i = 0; i < facilities.length; i++) {

						if ("1".equals(facilities[i])) {
							// wifi
							wifiImageView.setVisibility(View.VISIBLE);
						} else if ("5".equals(facilities[i])) {
							// parking
							parkingImageView.setVisibility(View.VISIBLE);
						}
					}
				}

				TextView hotelAddressTextView = (TextView) arg1
						.findViewById(R.id.hotelAddressTextView);
				hotelAddressTextView.setText(hotelInfo.hotelAddress);

				ViewGroup mapLayout = (ViewGroup) arg1
						.findViewById(R.id.mapLayout);
				mapLayout.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent intent = new Intent(mContext,
								HotelLocationMapActivity.class);
						intent.putExtra("GoogleLng",
								hotelInfo.latlng_1_coordinate);
						intent.putExtra("GoogleLat",
								hotelInfo.latlng_0_coordinate);
						intent.putExtra("HotelName", hotelInfo.hotelName);
						mContext.startActivity(intent);
					}
				});
				final ImageView collectImageView = (ImageView) arg1
						.findViewById(R.id.collectImageView);
				if ("0".equals(hotelInfo.collect)) {
					collectImageView
							.setImageResource(R.drawable.ic_hotel_collect_defatul);
				} else if ("1".equals(hotelInfo.collect)) {
					collectImageView
							.setImageResource(R.drawable.ic_hotel_collect_select);
				}
				ViewGroup collectLayout = (ViewGroup) arg1
						.findViewById(R.id.collectLayout);
				collectLayout.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						modifyCollectStatus(hotelInfo, collectImageView);
					}
				});

			}
		} else if (0 == mCurrentTab) {
			if (1 == arg0) {
				RadioButton radioButton1 = (RadioButton) arg1
						.findViewById(R.id.radio0);
				radioButton1.setOnCheckedChangeListener(this);
				RadioButton radioButton2 = (RadioButton) arg1
						.findViewById(R.id.radio1);
				radioButton2.setOnCheckedChangeListener(this);
				RadioButton radioButton3 = (RadioButton) arg1
						.findViewById(R.id.radio2);
				radioButton3.setOnCheckedChangeListener(this);
				switch (mCurrentTab) {
				case 0:
					radioButton1.setChecked(true);
					break;
				case 1:
					radioButton2.setChecked(true);
					break;
				case 2:
					radioButton3.setChecked(true);
					break;
				default:
					break;
				}
			} else if (2 == arg0) {

				setDateView(arg1);

			} else {
				if (mHotelList.get(arg0 - 3) instanceof RatePlanInfo) {

					ViewGroup noResultLayout = (ViewGroup) arg1
							.findViewById(R.id.noResultLayout);
					noResultLayout.setVisibility(View.GONE);
					ViewGroup hotelPriceLayout = (ViewGroup) arg1
							.findViewById(R.id.hotelPriceLayout);
					hotelPriceLayout.setVisibility(View.VISIBLE);

					RatePlanInfo ratePlanInfo = (RatePlanInfo) mHotelList
							.get(arg0 - 3);

					TextView roomNameTextView = (TextView) arg1
							.findViewById(R.id.roomNameTextView);
					String roomNameString = ratePlanInfo.RoomName;
					roomNameString = roomNameString.replace(" ", "");
					roomNameString = roomNameString.replace("（", "(");
					roomNameString = roomNameString.replace("）", ")");
					roomNameTextView.setText(roomNameString);

					TextView nrpNameTextView = (TextView) arg1
							.findViewById(R.id.nrpNameTextView);
					String nrpname = "";
					if (!"".equals(ratePlanInfo.nrpname)) {
						nrpNameTextView.setText("");
						nrpname = " - " + ratePlanInfo.nrpname;
					}

					SpannableStringBuilder spsb = new SpannableStringBuilder(
							roomNameString + nrpname);
					spsb.setSpan(new ForegroundColorSpan(mContext
							.getResources().getColor(android.R.color.black)),
							0, roomNameString.length(),
							Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
					float roomNameSize = mContext.getResources().getDimension(
							R.dimen.list_text_title_size);
					spsb.setSpan(new AbsoluteSizeSpan((int) roomNameSize), 0,
							roomNameString.length(),
							Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

					spsb.setSpan(new ForegroundColorSpan(
							R.color.list_gray_text_color), roomNameString
							.length(),
							roomNameString.length() + nrpname.length(),
							Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
					float nrpnameFloat = mContext.getResources().getDimension(
							R.dimen.list_text_small_size);
					spsb.setSpan(new AbsoluteSizeSpan((int) nrpnameFloat),
							roomNameString.length(), roomNameString.length()
									+ nrpname.length(),
							Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
					roomNameTextView.setText(spsb);

					ImageView prepayRuleImageView = (ImageView) arg1
							.findViewById(R.id.prepayRuleImageView);
					if (ratePlanInfo.PaymentType.equals("Prepay")) {
						prepayRuleImageView.setVisibility(View.VISIBLE);
					} else {
						prepayRuleImageView.setVisibility(View.GONE);
					}
					TextView descTextView = (TextView) arg1
							.findViewById(R.id.descTextView);
					if (null != ratePlanInfo.desction) {
						descTextView.setVisibility(View.VISIBLE);
						descTextView.setText(ratePlanInfo.desction.description);
					} else {
						descTextView.setVisibility(View.GONE);
					}
					TextView priceTextView = (TextView) arg1
							.findViewById(R.id.priceTextView);
					int money = 0;
					try {
						money = (int) (Float
								.parseFloat(ratePlanInfo.AverageRate));
					} catch (Exception e) {
					}
					SpannableStringBuilder moneySpannable = new SpannableStringBuilder(
							"￥" + money);
					moneySpannable.setSpan(
							new ForegroundColorSpan(mContext.getResources()
									.getColor(R.color.list_gray_text_color)),
							0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
					float moneySize = mContext.getResources().getDimension(
							R.dimen.list_text_small_size);
					moneySpannable.setSpan(
							new AbsoluteSizeSpan((int) moneySize), 0, 1,
							Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
					priceTextView.setText(moneySpannable);

					ViewGroup dikouLayout = (ViewGroup) arg1
							.findViewById(R.id.dikouLayout);
					if (!ratePlanInfo.PaymentType.equals("Prepay")
							|| null == mMemberManageds
							|| 0 == mMemberManageds.size()) {
						dikouLayout.setVisibility(View.GONE);
					} else {
						dikouLayout.setVisibility(View.VISIBLE);
						TextView dikouTextView = (TextView) arg1
								.findViewById(R.id.dikouTextView);
						int tempUscore = 0;
						try {
							tempUscore = Integer.parseInt(mMemberManageds
									.get(0).uscore);
						} catch (Exception e) {
						}
						if (tempUscore > money) {
							dikouTextView.setText(money + "");
						} else {
							dikouTextView
									.setText(mMemberManageds.get(0).uscore);
						}
						if ("0".equals(mMemberManageds.get(0).uscore)) {
							dikouLayout.setVisibility(View.GONE);
						}
					}

					ViewGroup fanLayout = (ViewGroup) arg1
							.findViewById(R.id.fanLayout);
					TextView fanTextView = (TextView) arg1
							.findViewById(R.id.fanTextView);
					if ("".equals(ratePlanInfo.Bonus)
							|| "0".equals(ratePlanInfo.Bonus)) {
						fanLayout.setVisibility(View.GONE);
					} else {
						fanLayout.setVisibility(View.VISIBLE);
						fanTextView.setText(ratePlanInfo.Bonus);
					}

					TextView bookingTextView = (TextView) arg1
							.findViewById(R.id.bookingTextView);
					if ("true".equalsIgnoreCase(ratePlanInfo.Status)) {
						bookingTextView.setText("预订");
						bookingTextView.setTextColor(mContext.getResources()
								.getColor(R.color.text_blue));
						bookingTextView
								.setBackgroundResource(R.drawable.btn_yuding);
					} else {
						bookingTextView.setText("满房");
						bookingTextView.setTextColor(mContext.getResources()
								.getColor(R.color.list_gray_text_color));
						bookingTextView
								.setBackgroundResource(R.drawable.btn_manfang);
					}
				} else if (mHotelList.get(arg0 - 3) instanceof String) {

					String string = (String) mHotelList.get(arg0 - 3);

					ViewGroup noResultLayout = (ViewGroup) arg1
							.findViewById(R.id.noResultLayout);
					noResultLayout.setVisibility(View.VISIBLE);
					ViewGroup hotelPriceLayout = (ViewGroup) arg1
							.findViewById(R.id.hotelPriceLayout);
					hotelPriceLayout.setVisibility(View.GONE);
					TextView noResultTextView = (TextView) arg1
							.findViewById(R.id.noResultTextView);
					noResultTextView.setText(string);
					noResultLayout.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View arg0) {

						}
					});
				}
			}
		} else {
			if (1 == arg0) {
				RadioButton radioButton1 = (RadioButton) arg1
						.findViewById(R.id.radio0);
				radioButton1.setOnCheckedChangeListener(this);
				RadioButton radioButton2 = (RadioButton) arg1
						.findViewById(R.id.radio1);
				radioButton2.setOnCheckedChangeListener(this);
				RadioButton radioButton3 = (RadioButton) arg1
						.findViewById(R.id.radio2);
				radioButton3.setOnCheckedChangeListener(this);
				switch (mCurrentTab) {
				case 0:
					radioButton1.setChecked(true);
					break;
				case 1:
					radioButton2.setChecked(true);
					break;
				case 2:
					radioButton3.setChecked(true);
					break;
				default:
					break;
				}
			} else {
				ViewGroup hotelReviewLayout = (ViewGroup) arg1
						.findViewById(R.id.hotelReviewLayout);
				hotelReviewLayout.setVisibility(View.GONE);
				ViewGroup hotelInfoLayout = (ViewGroup) arg1
						.findViewById(R.id.hotelInfoLayout);
				hotelInfoLayout.setVisibility(View.GONE);
				ViewGroup noResultLayout = (ViewGroup) arg1
						.findViewById(R.id.noResultLayout);
				noResultLayout.setVisibility(View.GONE);
				if (1 == mCurrentTab) {

					if (mHotelList.get(arg0 - 2) instanceof HotelReviews) {
						// 评论
						final HotelReviews hotelReviews = (HotelReviews) mHotelList
								.get(arg0 - 2);
						hotelReviewLayout.setVisibility(View.VISIBLE);

						TextView nameTextView = (TextView) arg1
								.findViewById(R.id.nameTextView);
						TextView createDateTextView = (TextView) arg1
								.findViewById(R.id.createDateTextView);
						// 语音
						ViewGroup voiceLayout = (ViewGroup) arg1
								.findViewById(R.id.voiceLayout);
						ViewGroup playRecordLayout = (ViewGroup) arg1
								.findViewById(R.id.playRecordLayout);
						ImageView playAnimImageView = (ImageView) arg1
								.findViewById(R.id.playAnimImageView);
						TextView recordLenghtTextView = (TextView) arg1
								.findViewById(R.id.recordLenghtTextView);
						// 文字评论
						TextView contentTextView = (TextView) arg1
								.findViewById(R.id.contentTextView);

						createDateTextView.setText(hotelReviews.adddate);
						nameTextView.setText(hotelReviews.guest_name);

						final View tempView = arg1;

						// 语音
						if (!TextUtils.isEmpty(hotelReviews.voiceurl)) {
							voiceLayout.setVisibility(View.VISIBLE);
							contentTextView.setVisibility(View.GONE);
							recordLenghtTextView.setText(hotelReviews.voicetime
									+ "”");
							int voiceTime = 0;
							try {
								voiceTime = Integer
										.parseInt(hotelReviews.voicetime);
							} catch (Exception e) {
							}
							playRecordLayout
									.setOnClickListener(new OnClickListener() {

										@Override
										public void onClick(View view) {
											// 播放
											downLoadVoice(hotelReviews,
													tempView, arg0);
										}
									});

							ViewGroup playRecordBgLayout = (ViewGroup) arg1
									.findViewById(R.id.playRecordBgLayout);
							int screenWidth = ScreenUtils
									.getScreenBounds(mContext)[0];
							int playRecordBgWidth = screenWidth
									- ToolUtils.dipToPx(mContext, 10) * 2
									- ToolUtils.dipToPx(mContext, 50) * 2;
							int per = playRecordBgWidth
									/ mRecorder.getRecordMaxLenght();
							playRecordBgWidth = voiceTime * per;
							LayoutParams layoutParams = new RelativeLayout.LayoutParams(
									playRecordBgWidth
											+ ToolUtils.dipToPx(mContext, 50),
									LayoutParams.WRAP_CONTENT);
							playRecordBgLayout.setLayoutParams(layoutParams);

							AnimationDrawable animationDrawable = (AnimationDrawable) playAnimImageView
									.getDrawable();
							if (null != animationDrawable
									) {
								animationDrawable.stop();
								playAnimImageView.setImageDrawable(mContext
										.getResources().getDrawable(
												R.anim.record_play_wait_xml));
							}
							// 从新设置播放动画
							if (-1 != mPlayAnimPosition && arg0 == mPlayAnimPosition) {
								DebugLog.logI("getView mPlayAnimPosition : "
										+ mPlayAnimPosition);
								DebugLog.logI("getView arg0 : "
										+ arg0);
								mAnimationDrawable = (AnimationDrawable) playAnimImageView
										.getDrawable();
								mAnimationDrawable.start();
								lastPlayAnimImageView = playAnimImageView;
							}
						} else {
							// 文字
							voiceLayout.setVisibility(View.GONE);
							contentTextView.setVisibility(View.VISIBLE);
							contentTextView.setText(hotelReviews.content);
						}

					} else if (mHotelList.get(arg0 - 2) instanceof String) {
						hotelReviewLayout.setVisibility(View.GONE);
						hotelInfoLayout.setVisibility(View.GONE);
						String string = (String) mHotelList.get(arg0 - 2);
						noResultLayout.setVisibility(View.VISIBLE);
						TextView noResultTextView = (TextView) arg1
								.findViewById(R.id.noResultTextView);
						noResultTextView.setText(string);
					}
				} else {
					if (2 == mCurrentTab) {
						// 酒店信息
						if (1 == mHotelInfos.size()) {
							final HotelInfo hotelInfo = mHotelInfos.get(0);
							hotelInfoLayout.setVisibility(View.VISIBLE);
							TextView infoFlagTextView = (TextView) arg1
									.findViewById(R.id.infoFlagTextView);
							TextView infoTextView = (TextView) arg1
									.findViewById(R.id.infoTextView);
							mHotelInfos.get(0);
							if (2 == arg0) {
								infoFlagTextView.setText("开业时间");
								infoTextView.setText(hotelInfo.descriPtion);
							} else if (3 == arg0) {
								infoFlagTextView.setText("酒店设施");
								if (!"".equals(hotelInfo.facilities)) {
									String[] facilities = hotelInfo.facilities
											.split(",");
									StringBuilder stringBuilder = new StringBuilder();
									for (int i = 0; i < facilities.length; i++) {
										int index = -1;
										try {
											index = Integer
													.parseInt(facilities[i]);
										} catch (Exception e) {
										}
										if (-1 != index) {
											stringBuilder
													.append(getFacilitieWithIndex(index))
													.append(" ");
										}
									}
									infoTextView.setText(stringBuilder
											.toString());
								}
							} else if (4 == arg0) {
								infoFlagTextView.setText("酒店简介");
								infoTextView.setText(hotelInfo.introeDitor);
							}
						} else {
							hotelReviewLayout.setVisibility(View.GONE);
							hotelInfoLayout.setVisibility(View.GONE);
							noResultLayout.setVisibility(View.VISIBLE);
							TextView noResultTextView = (TextView) arg1
									.findViewById(R.id.noResultTextView);
							noResultTextView.setText("暂无酒店信息");
						}
					}
				}
			}
		}

		return arg1;
	}

	public void setRadio0OnCheckedChangeListener(
			OnCheckedChangeListener onCheckedChangeListener) {
		mRadio0OnCheckedChangeListener = onCheckedChangeListener;
	}

	public void setRadio1OnCheckedChangeListener(
			OnCheckedChangeListener onCheckedChangeListener) {
		mRadio1OnCheckedChangeListener = onCheckedChangeListener;
	}

	public void setRadio2OnCheckedChangeListener(
			OnCheckedChangeListener onCheckedChangeListener) {
		mRadio2OnCheckedChangeListener = onCheckedChangeListener;
	}

	public void setCurrentTab(int index) {
		mCurrentTab = index;
	}

	public int getCurrentTab() {
		return mCurrentTab;
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		RadioButton radioButton0 = (RadioButton) mTabView
				.findViewById(R.id.radio0);
		RadioButton radioButton1 = (RadioButton) mTabView
				.findViewById(R.id.radio1);
		RadioButton radioButton2 = (RadioButton) mTabView
				.findViewById(R.id.radio2);

		switch (buttonView.getId()) {
		case R.id.radio0: {
			if (radioButton0.isChecked()) {
				return;
			}
			if (null != mRadio0OnCheckedChangeListener) {
				mRadio0OnCheckedChangeListener.onCheckedChanged(buttonView,
						isChecked);
			}
			if (isChecked) {
				mCurrentTab = 0;
			}
			break;
		}
		case R.id.radio1: {
			if (radioButton1.isChecked()) {
				return;
			}
			if (null != mRadio1OnCheckedChangeListener) {
				mRadio1OnCheckedChangeListener.onCheckedChanged(buttonView,
						isChecked);
			}
			if (isChecked) {
				mCurrentTab = 1;
			}
			break;
		}
		case R.id.radio2: {
			if (radioButton2.isChecked()) {
				return;
			}
			if (null != mRadio2OnCheckedChangeListener) {
				mRadio2OnCheckedChangeListener.onCheckedChanged(buttonView,
						isChecked);
			}
			if (isChecked) {
				mCurrentTab = 2;
			}
			break;
		}
		default:
			break;
		}

	}

	private void setDateView(View view) {
		String start = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.getStartDate(), "yyyyMMdd"),
				"MM月dd日");
		String end = DateUtils.dateFormat(DateUtils.getDateMillis(
				mApplication.mHotelSearchCondition.getEndDate(), "yyyyMMdd"),
				"MM月dd日");

		TextView inDateTextView = (TextView) view
				.findViewById(R.id.inDateTextView);
		TextView outDateTextView = (TextView) view
				.findViewById(R.id.outTextView);
		inDateTextView.setText(start);
		outDateTextView.setText(end);

		ViewGroup dikouDescLayout = (ViewGroup) view
				.findViewById(R.id.dikouDescLayout);
		if ("0".equals(mDeduction) || null == mMemberManageds
				|| 0 == mMemberManageds.size()
				|| "0".equals(mMemberManageds.get(0).uscore)) {
			dikouDescLayout.setVisibility(View.GONE);
		} else {
			dikouDescLayout.setVisibility(View.VISIBLE);
			TextView dikouDescMoneyTextView = (TextView) view
					.findViewById(R.id.dikouDescMoneyTextView);
			dikouDescMoneyTextView.setText(mMemberManageds.get(0).uscore);
		}
	}

	private String getFacilitieWithIndex(int index) {
		switch (index) {
		case 1:
			return "免费Wifi";

		case 2:
			return "免费Wifi";

		case 3:
			return "免费宽带";

		case 4:
			return "收费宽带";

		case 5:
			return "免费停车场";

		case 6:
			return "收费停车场";

		case 7:
			return "免费接机服务";

		case 8:
			return "收费接机服务";

		case 9:
			return "室内游泳池";

		case 10:
			return "室外游泳池";

		case 11:
			return "健身房";

		case 12:
			return "商务中心";

		case 13:
			return "会议室";

		case 14:
			return "酒店餐厅";

		default:
			return null;

		}
	}

	/*
	 * 添加收藏酒店
	 */
	private void addcollection(final HotelInfo hotelInfo,
			final ImageView imageView) {
		NetworkClient.getNetworkClient().PostRequest(
				new AddCollectionRequest(mContext, hotelInfo.hotelId),
				new AddCollectionResponse() {
					@Override
					public void onResponse(
							ResponseHandlerInterface responseHandlerInterface) {
						if (0 == status) {
							if (!TextUtils.isEmpty(messageString)) {
								HandlerToastUI.getHandlerToastUI(mContext,
										"添加收藏" + messageString);
							}
							HandlerPostUI.getHandlerPostUI(new Runnable() {

								@Override
								public void run() {
									hotelInfo.collect = "1";
									imageView
											.setImageResource(R.drawable.ic_hotel_collect_select);
								}
							});
						} else {
							HandlerToastUI.getHandlerToastUI(mContext, "收藏失败");
						}
					}
				});
	}

	/*
	 * 删除收藏酒店
	 */
	private void deletecollection(final HotelInfo hoteinInfo,
			final ImageView imageView) {
		NetworkClient.getNetworkClient().PostRequest(
				new DeleteCollectionRequest(mContext, hoteinInfo.hotelId),
				new DeleteCollectionResponse() {
					@Override
					public void onResponse(
							ResponseHandlerInterface responseHandlerInterface) {
						if (0 == status) {
							if (!TextUtils.isEmpty(messageString)) {
								HandlerToastUI.getHandlerToastUI(mContext,
										"取消收藏" + messageString);
							}
							HandlerPostUI.getHandlerPostUI(new Runnable() {

								@Override
								public void run() {
									hoteinInfo.collect = "0";
									imageView
											.setImageResource(R.drawable.ic_hotel_collect_defatul);
								}
							});
						} else {
							HandlerToastUI
									.getHandlerToastUI(mContext, "取消收藏失败");
						}
					}
				});
	}

	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (resultCode) {
		case Activity.RESULT_OK: {

			break;
		}
		case Activity.RESULT_CANCELED: {
			break;
		}
		default:
			break;
		}
	}

	/**
	 * 修改收藏状态
	 */
	private void modifyCollectStatus(HotelInfo hotelInfo,
			ImageView collectImageView) {

		if (!"".equals(AppUserId.getUserId(mContext))) {

			((Activity) mContext).setResult(Activity.RESULT_OK);
			if ("0".equals(hotelInfo.collect)) {
				addcollection(hotelInfo, collectImageView);
			} else if ("1".equals(hotelInfo.collect)) {
				deletecollection(hotelInfo, collectImageView);
			}
		} else {
			// Intent intent = new Intent(mContext, WXEntryActivity.class);
			Intent intent = new Intent(mContext, LoginActivity.class);
			((Activity) mContext).startActivityForResult(intent, 2);
		}

	}

	private void downLoadVoice(final HotelReviews hotelReviews,
			final View view, final int position) {
		String tempPicUrlString = hotelReviews.voiceurl;
		if (tempPicUrlString.startsWith("http://")) {

		} else {
			tempPicUrlString = "http://" + tempPicUrlString;
		}
		final String picUrlString = tempPicUrlString;

		// 判断缓存
		String fname = picUrlString
				.substring(picUrlString.lastIndexOf("/") + 1);
		fname = SAVE_VOICE_PATH + fname;
		File recordFile = new File(fname);
		if (recordFile.exists()) {
			// 有缓存播放

			playRecorder(fname, view, position);

			return;
		}

		NetworkClient.getNetworkClient().GetRequest(
				new DownLoadRequest(mContext, picUrlString),
				new DownLoadResponse() {
					@Override
					public void onSuccess(int statusCode, Header[] headers,
							byte[] binaryData, HttpResponse response) {
						super.onSuccess(statusCode, headers, binaryData,
								response);
						String fname = picUrlString.substring(picUrlString
								.lastIndexOf("/") + 1);
						fname = SAVE_VOICE_PATH + fname;
						final String tempFname = fname;
						final boolean result = saveRecorder(binaryData,
								new File(fname));
						if (!result) {
							HandlerToastUI
									.getHandlerToastUI(mContext, "下载录音失败");
							return;
						}
						HandlerPostUI.getHandlerPostUI(new Runnable() {

							@Override
							public void run() {
								playRecorder(tempFname, view, position);
							}
						});
					}

					@Override
					public void onFailure(int statusCode, Header[] headers,
							byte[] binaryData, Throwable error) {
					}
				});
	}

	private void playRecorder(String pathString, View view, int position) {
		
		if(mPlayAnimPosition == position){
			if(mRecorder.getState() == Recorder.PLAYING_STATE){
				mPlayAnimPosition = -1;
				mRecorder.stopPlayback();
				if (null != mAnimationDrawable && mAnimationDrawable.isRunning()
						&& null != lastPlayAnimImageView) {
					mAnimationDrawable.stop();
					lastPlayAnimImageView.setImageDrawable(mContext.getResources()
							.getDrawable(R.anim.record_play_wait_xml));
				}
				return ;
			}
		}
		
		mRecorder.startPlayback(pathString);
		ImageView playAnimImageView = (ImageView) view
				.findViewById(R.id.playAnimImageView);
		if (null != mAnimationDrawable && mAnimationDrawable.isRunning()
				&& null != lastPlayAnimImageView) {
			mAnimationDrawable.stop();
			lastPlayAnimImageView.setImageDrawable(mContext.getResources()
					.getDrawable(R.anim.record_play_wait_xml));
		}
		mPlayAnimPosition = position;
		DebugLog.logI("set mPlayAnimPosition : " + mPlayAnimPosition);
		mAnimationDrawable = (AnimationDrawable) playAnimImageView
				.getDrawable();
		mAnimationDrawable.start();
		lastPlayAnimImageView = playAnimImageView;
	}

	private boolean saveRecorder(byte[] recorderByte, File file) {
		boolean result = true;
		File pathFile = new File(file.getAbsolutePath().substring(0,
				file.getAbsolutePath().lastIndexOf("/")));
		try {
			if (!pathFile.exists()) {
				try {
					pathFile.mkdirs();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (!file.exists()) {

				try {
					file.createNewFile();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			FileOutputStream fileOutputStream = new FileOutputStream(file);
			try {
				fileOutputStream.write(recorderByte, 0, recorderByte.length);
				fileOutputStream.flush();
			} catch (IOException e) {
				e.printStackTrace();
				result = false;
			} finally {
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			result = false;
		}
		return result;
	}

}